package com.definity.toolkit.web.taglib;

import javax.servlet.jsp.JspException;

public class EnumTag extends BaseTag {

	private static final long serialVersionUID = -6435663945142295689L;

	private String enumerated;
	private Object value;

	public EnumTag() {

	}

	public void setEnumerated(String enumerated) {
		this.enumerated = enumerated;
	}

	public void setValue(Object value) {
		this.value = value;
	}

	@Override
	public int doStartTag() throws JspException {
		return SKIP_BODY;
	}

	@Override
	public int doEndTag() throws JspException {
		if (value == null) {
			return super.doEndTag();
		}
		
		try {
			Class<?> enumType = Class.forName(enumerated);
			String item = enumType.getSimpleName() + "." + value.toString();
			String label = i18n().tl(item);
			
			write(label);
		} catch (Exception e) {
			throw new JspException(e);
		}

		return super.doEndTag();
	}

}
